﻿//
// Created by Grishul Eugeny
//
// See license in License.txt
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Runtime.InteropServices;
using NCommander.Core;

namespace NCommander.IconProviders
{
	internal sealed class Win32Shell : IIconProvider
	{
		public static readonly Win32Shell Instance = new Win32Shell();

		#region IIconProvider Members

		public Icon GetIcon( string path )
		{
			Win32.SHFILEINFO shellFileInfo = new Win32.SHFILEINFO();
			//Win32.SHGetFileInfo( path, 0, ref shellFileInfo, ( uint ) Marshal.SizeOf( shellFileInfo ), Win32.SHGFI_ICON | Win32.SHGFI_SMALLICON | Win32.SHGFI_ADDOVERLAYS );
			Win32.SHGetFileInfo( path, 0, ref shellFileInfo, ( uint ) Marshal.SizeOf( shellFileInfo ), Win32.SHGFI_ICON | Win32.SHGFI_ADDOVERLAYS );

			Icon result = null;
				
			if(shellFileInfo.hIcon != IntPtr.Zero)
				result = Icon.FromHandle( shellFileInfo.hIcon ).Clone() as Icon; 		
			Win32.DestroyIcon( shellFileInfo.hIcon );
	
			return result;
		}

		#endregion
	}
}
